import { Controller, Get, Post, Put, Body, Query, Param, Delete, BadRequestException } from '@nestjs/common';
import { ApiTags, ApiOperation, ApiBearerAuth } from '@nestjs/swagger';
import { RequirePermission } from 'src/common/decorators/require-premission.decorator';
import { IssuesService } from './issues.service';
import { CreateIssuesDto, BaseIssuesDto, UpdateIssuesDto, QueryIssuesDto, ListIssuesDto } from './dto/issues.dto';
import { ApiDataResponse } from 'src/common/decorators/apiDataResponse.decorator';
import { NotRequireAuth } from "../user/user.decorator";

@ApiTags('育儿心理问题表')
@Controller('system/issues')
@ApiBearerAuth('Authorization')
export class IssuesController {
  constructor(private readonly issuesService: IssuesService) {}

  @ApiOperation({ summary: '育儿心理问题表-创建' })
  @ApiDataResponse(BaseIssuesDto)
  @RequirePermission('system:issues:add')
  @Post()
  create(@Body() body: CreateIssuesDto) {
    return this.issuesService.create(body);
  }

  @ApiOperation({ summary: '育儿心理问题表-列表' })
  @ApiDataResponse(ListIssuesDto, true, true)
  // @RequirePermission('system:issues:list')
  @Get('/list')
  findAll(@Query() query: QueryIssuesDto) {
    return this.issuesService.findAll(query);
  }

  @ApiOperation({ summary: '育儿心理问题表-列表' })
  @ApiDataResponse(ListIssuesDto, true, true)
  // @RequirePermission('system:issues:list')
  @NotRequireAuth()
  @Get('/randList/:userId')
  randList(@Param('userId') userId: number) {
    if (!userId) {
      throw new BadRequestException('用户ID不能为空');
    }
    return this.issuesService.randList(userId);
  }

  @ApiOperation({ summary: '育儿心理问题表-详情' })
  @ApiDataResponse(BaseIssuesDto)
  @RequirePermission('system:issues:query')
  @Get(':id')
  findOne(@Param('id') id: number) {
    return this.issuesService.findOne(id);
  }

  @ApiOperation({ summary: '育儿心理问题表-修改' })
  @ApiDataResponse()
  @RequirePermission('system:issues:edit')
  @Put()
  update(@Body() body: UpdateIssuesDto) {
    return this.issuesService.update(body);
  }

  @ApiOperation({ summary: '育儿心理问题表-删除' })
  @ApiDataResponse()
  @RequirePermission('system:issues:remove')
  @Delete(':id')
  remove(@Param('id') id: string) {
    const ids = id.split(',').map((id) => +id);
    return this.issuesService.remove(ids);
  }
}
